package edu.ccut.saturn.studio.validate.part;

import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.ui.dialogs.TypeSelectionDialog2;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnProjectUtil;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnSWTUtils;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnSectionPart;
import edu.ccut.saturn.studio.core.util.eclipse.SaturnValidation;
import edu.ccut.saturn.studio.saturndata.model.ValidateModel;
import edu.ccut.saturn.studio.saturndata.model.ValidateVO;
import edu.ccut.saturn.studio.validate.common.JavaScriptSet;
import edu.ccut.saturn.studio.validate.dialog.CreateClassDialog;
import edu.ccut.saturn.studio.validate.dialog.ErrValidateDialog;
import edu.ccut.saturn.studio.validate.dialog.ErrValidateModefiyDialog;
import edu.ccut.saturn.studio.validate.editor.ValidateEditor;
//import edu.ccut.saturn.studio.validate.vo.ValidateVO;

public class ValidatePart extends SaturnSectionPart {

	private static final String ARGDIALOG_ELEMENT_ARG = "arg"; //$NON-NLS-1$

	private static final String ARGDIALOG_ELEMENT_ID = "ID"; //$NON-NLS-1$

	private static final String ERRORDIALOG_ELEMENT_VALUE = "value"; //$NON-NLS-1$

	private static final String ERRORDIALOG_ELEMENT_KEY = "key"; //$NON-NLS-1$

	private Table ErrInfoTable;

	private TableViewer argsTableViewer;
	private Table argstable;
	private Text classText;
	private Text nameText;
	private Text keyText;
	private Text descriptionText;
	private Text cusValText;
	private Text jsValText;
	private TableViewer tableViewerErrInfo;
	private TableLabelProvider tableLabelProvider = null;
	private ValidateVO validate;

	private IProject project = null;

	private ValidateModel validateModel;

	public ValidatePart(Composite parent, IManagedForm form, ValidateEditor ve) {
		super(parent, form);
		this.validateModel = ve.getValidateModel();
		this.validate =  validateModel.getValidateVO();
		getSection().setClient(createClient(form));
		this.project = SaturnProjectUtil.getProject(ve.getEditorInput());
	}

	public void dispose() {

	}

	Control createClient(IManagedForm form) {
		FormToolkit toolkit = form.getToolkit();
		Composite composite = new Composite(getSection(), SWT.NULL);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 4;
		composite.setLayout(gridLayout);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		GridData gridDataText2 = new GridData(SWT.FILL, SWT.CENTER, true,
				false, 2, 1);

		final Label label_2 = new Label(composite, SWT.NONE);
		label_2.setLayoutData(new GridData());
		label_2.setText(Messages
				.getString("ValidateFilePropertiesPart.validateclass")); //$NON-NLS-1$

		GridData gridDataText1 = new GridData(SWT.FILL, SWT.CENTER, true, false);

		classText = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		classText.setTextLimit(100);
		classText.setLayoutData(gridDataText1);
		classText.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				classTextChange(classText.getText());
			}
		});
		final Button browerButton = new Button(composite, SWT.NONE);
		browerButton.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings( { "deprecation", "restriction" })//$NON-NLS-1$ //$NON-NLS-2$
			public void widgetSelected(final SelectionEvent e) {
				IJavaSearchScope searchScope = SearchEngine
						.createWorkspaceScope();
				TypeSelectionDialog2 dialog = new TypeSelectionDialog2(null,
						false, new ProgressMonitorDialog(null), searchScope,
						IJavaSearchConstants.TYPE);
				dialog
						.setMessage(Messages
								.getString("ValidateFilePropertiesPart.pleasewritevalidatename")); //$NON-NLS-1$
				dialog.setBlockOnOpen(true);
				dialog
						.setTitle(Messages
								.getString("ValidateFilePropertiesPart.choosevalidateclass")); //$NON-NLS-1$
				if (Dialog.OK == dialog.open()) {
					IType obj = (IType) dialog.getFirstResult();
					classText.setText(obj.getFullyQualifiedName());
				}
			}
		});
		browerButton.setText(Messages
				.getString("ValidateFilePropertiesPart.browsing")); //$NON-NLS-1$
		browerButton.setLayoutData(new GridData());

		GridData buttonG = new GridData(SWT.CENTER, SWT.CENTER, false, false);
		buttonG.widthHint = 60;

		final Button createClassButton = new Button(composite, SWT.NONE);
		createClassButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				CreateClassDialog classDialog = new CreateClassDialog(
						getSection().getShell(), project, ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				if (classDialog.open() == IDialogConstants.OK_ID) {
					classText.setText(classDialog.getPkgName()
							+ "." + classDialog.getClassName()); //$NON-NLS-1$
				}
			}
		});
		createClassButton.setLayoutData(buttonG);
		createClassButton.setText(Messages
				.getString("ValidateFilePropertiesPart.create")); //$NON-NLS-1$

		final Label label = new Label(composite, SWT.NONE);
		label.setLayoutData(new GridData());
		label.setText(Messages.getString("ValidatePart.id")); //$NON-NLS-1$

		keyText = new Text(composite, SWT.READ_ONLY | SWT.BORDER);
		keyText.setTextLimit(100);
		keyText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false,
				2, 1));

		Label label100 = new Label(composite, SWT.NONE);
		label100.setText(""); //$NON-NLS-1$

		final Label label_1 = new Label(composite, SWT.NONE);
		label_1.setLayoutData(new GridData());
		label_1.setText(Messages.getString("ValidatePart.validatename")); //$NON-NLS-1$

		nameText = new Text(composite, SWT.READ_ONLY | SWT.BORDER);
		nameText.setTextLimit(50);
		nameText.setLayoutData(gridDataText2);

		label100 = new Label(composite, SWT.NONE);
		label100.setText(""); //$NON-NLS-1$

		final Label label_3 = new Label(composite, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
		label_3.setText(Messages.getString("ValidatePart.description")); //$NON-NLS-1$

		descriptionText = new Text(composite, SWT.BORDER | SWT.V_SCROLL
				| SWT.WRAP);
		descriptionText.setTextLimit(200);
		final GridData gd_DesValText = new GridData(SWT.FILL, SWT.FILL, true,
				true, 2, 1);
		gd_DesValText.heightHint = 50;
		descriptionText.setLayoutData(gd_DesValText);
		descriptionText.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				descriptionTextChange(descriptionText.getText());
			}
		});
		label100 = new Label(composite, SWT.NONE);
		label100.setText(""); //$NON-NLS-1$

		final Label jsLabel = new Label(composite, SWT.NONE);
		jsLabel.setLayoutData(new GridData());
		jsLabel.setText(Messages
				.getString("ValidateFilePropertiesPart.jsvalidate")); //$NON-NLS-1$

		jsValText = new Text(composite, SWT.BORDER);
		jsValText.setTextLimit(50);
		final GridData gd_jsValText = new GridData(SWT.FILL, SWT.CENTER, true,
				false, 2, 1);
		jsValText.setLayoutData(gd_jsValText);
		// setJsValText(validateModel);
		jsValText.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				jsTextChange(JavaScriptSet.zhToEnJs(jsValText.getText()));
			}
		});
		new Label(composite, SWT.NONE);

		final Label cusJsLabel = new Label(composite, SWT.NONE);
		cusJsLabel
				.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
		cusJsLabel.setText(Messages
				.getString("ValidateFilePropertiesPart.userdefinejsvalidate")); //$NON-NLS-1$

		cusValText = new Text(composite, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP
				| SWT.H_SCROLL);
		cusValText.setTextLimit(1000);
		final GridData gd_cusValText = new GridData(SWT.FILL, SWT.FILL, true,
				true, 2, 1);
		gd_cusValText.heightHint = 62;
		cusValText.setLayoutData(gd_cusValText);
		cusValText.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				cusJsTextChange(cusValText.getText());
			}
		});
		new Label(composite, SWT.NONE);

		final Label label_4 = new Label(composite, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
		label_4.setText(Messages
				.getString("ValidateFilePropertiesPart.parameterlist")); //$NON-NLS-1$

		argsTableViewer = new TableViewer(composite, SWT.BORDER
				| SWT.FULL_SELECTION);
		argstable = argsTableViewer.getTable();
		argstable.setLinesVisible(true);
		argstable.setHeaderVisible(true);
		GridData gridDataTable = new GridData(SWT.FILL, SWT.FILL, true, true,
				2, 1);
		argstable.setLayoutData(gridDataTable);

		final TableColumn newColumnTableColumn = new TableColumn(argstable,
				SWT.NONE);
		newColumnTableColumn.setWidth(90);
		newColumnTableColumn.setText(Messages
				.getString("ValidateFilePropertiesPart.no")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_1 = new TableColumn(argstable,
				SWT.NONE);
		newColumnTableColumn_1.setWidth(196);
		newColumnTableColumn_1.setText(Messages
				.getString("ValidatePart.parameter")); //$NON-NLS-1$

		argsTableViewer
				.setContentProvider(new SaturnSWTUtils.SaturnTableViewerDefaultContentProvider());

		tableLabelProvider = new TableLabelProvider();

		tableLabelProvider.setRowid(0);
		argsTableViewer.setLabelProvider(tableLabelProvider);

		modifyParameter();

		GridData gridData2 = new GridData();
		gridData2.horizontalAlignment = GridData.FILL;
		gridData2.grabExcessHorizontalSpace = false;
		gridData2.grabExcessVerticalSpace = false;
		gridData2.verticalAlignment = GridData.FILL;
		Composite buttonGroup = new Composite(composite, SWT.NONE);
		buttonGroup.setLayout(new GridLayout());
		buttonGroup.setLayoutData(gridData2);

		final Button addButton = new Button(buttonGroup, SWT.NONE);
		addButton.setText(Messages.getString("ValidateFilePropertiesPart.add")); //$NON-NLS-1$
		addButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doAdd();
			}
		});

		final Button editorButton = new Button(buttonGroup, SWT.NONE);
		editorButton.setText(Messages
				.getString("ValidateFilePropertiesPart.edit")); //$NON-NLS-1$
		editorButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doEdit();
			}
		});

		final Button delButton = new Button(buttonGroup, SWT.NONE);
		delButton.setText(Messages
				.getString("ValidateFilePropertiesPart.delete")); //$NON-NLS-1$
		delButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doRemove();
			}
		});

		final Button upButton = new Button(buttonGroup, SWT.NONE);
		upButton.setText(Messages
				.getString("ValidateFilePropertiesPart.upmove")); //$NON-NLS-1$
		upButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doUp();
			}
		});

		final Button downButton = new Button(buttonGroup, SWT.NONE);
		downButton.setText(Messages
				.getString("ValidateFilePropertiesPart.downmove")); //$NON-NLS-1$
		downButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				doDown();
			}
		});

		// final Button jsBrowerButton = new Button(composite, SWT.NONE);
		// jsBrowerButton.addSelectionListener(new SelectionAdapter() {
		// public void widgetSelected(final SelectionEvent e) {
		// ElementListSelectionDialog dialog = new ElementListSelectionDialog(
		// getSection().getShell(),
		// new SaturnSWTUtils.SaturnLabelDefaultProvider() {
		// public Image getImage(Object element) {
		// return Activator
		// .getImage(Images.DATABASE_CONNECTION);
		// }
		//
		// public String getText(Object element) {
		// String str = (String) element;
		// return str;
		// }
		// });
		// dialog.setTitle(Messages
		// .getString("ValidateFilePropertiesPart.55")); //$NON-NLS-1$
		// dialog.setMessage(Messages
		// .getString("ValidateFilePropertiesPart.56")); //$NON-NLS-1$
		// dialog.setElements(JavaScriptSet.javaScripts);
		// if (dialog.open() == Window.OK) {
		// jsValText.setText((String) dialog.getFirstResult());
		// }
		// }
		// });
		// jsBrowerButton.setLayoutData(gridData3);
		// jsBrowerButton.setText(Messages
		// .getString("ValidateFilePropertiesPart.54")); //$NON-NLS-1$

		final Label valErrMesLabel = new Label(composite, SWT.NONE);
		valErrMesLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false,
				false));
		valErrMesLabel.setText(Messages
				.getString("ValidateFilePropertiesPart.validateerrormessage")); //$NON-NLS-1$

		tableViewerErrInfo = new TableViewer(composite, SWT.FULL_SELECTION
				| SWT.BORDER);
		ErrInfoTable = tableViewerErrInfo.getTable();
		toolkit.adapt(ErrInfoTable, true, true);
		ErrInfoTable.setLinesVisible(true);
		ErrInfoTable.setHeaderVisible(true);
		final GridData gd_table_1 = new GridData(SWT.FILL, SWT.TOP, true, true,
				2, 1);
		gd_table_1.widthHint = 295;
		gd_table_1.heightHint = 65;
		ErrInfoTable.setLayoutData(gd_table_1);

		final TableColumn newColumnTableColumn_2 = new TableColumn(
				ErrInfoTable, SWT.NONE);
		newColumnTableColumn_2.setWidth(100);
		newColumnTableColumn_2.setText(Messages
				.getString("ValidateFilePropertiesPart.key")); //$NON-NLS-1$

		final TableColumn newColumnTableColumn_3 = new TableColumn(
				ErrInfoTable, SWT.NONE);
		newColumnTableColumn_3.setWidth(100);
		newColumnTableColumn_3.setText(Messages
				.getString("ValidateFilePropertiesPart.errorkey")); //$NON-NLS-1$

		tableViewerErrInfo
				.setLabelProvider(new SaturnSWTUtils.SaturnTableViewerDefaultLabelProvider() {

					@Override
					public String getColumnText(Object obj, int index) {
						String[] errorInfos = obj.toString().split("::"); //$NON-NLS-1$

						return errorInfos[index];
					}
				});
		tableViewerErrInfo
				.setContentProvider(new SaturnSWTUtils.SaturnTableViewerDefaultContentProvider() {
					@SuppressWarnings("unchecked")//$NON-NLS-1$
					public Object[] getElements(Object inputElement) {
						Map<String, String> errorInfo = (Map<String, String>) inputElement;

						Object[] input = new String[errorInfo.size()];

						int i = 0;
						for (String key : errorInfo.keySet()) {
							input[i++] = key + "::" + errorInfo.get(key); //$NON-NLS-1$
						}

						return input;
					}

				});

		tableViewerErrInfo.setInput(this.validate.getErrorInfos());

		final Composite buttonGroup_1 = new Composite(composite, SWT.NONE);
		final GridData gridData2_1 = new GridData(SWT.FILL, SWT.FILL, false, false);
		buttonGroup_1.setLayoutData(gridData2_1);
		buttonGroup_1.setLayout(new GridLayout());
		toolkit.adapt(buttonGroup_1);

		final Button buttonErrAdd = new Button(buttonGroup_1, SWT.NONE);
		buttonErrAdd.setLayoutData(new GridData(59, SWT.DEFAULT));
		toolkit.adapt(buttonErrAdd, true, true);
		buttonErrAdd.setText(Messages
				.getString("ValidateFilePropertiesPart.add")); //$NON-NLS-1$
		buttonErrAdd.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				Map<String, String> errors = validate.getErrorInfos();
				ErrValidateDialog errDialog = new ErrValidateDialog(Display
						.getDefault().getShells()[0], errors);
				if (errDialog.open() == InputDialog.OK) {
					tableViewerErrInfo.setInput(errors);
					validateModel.updateErrorinfo(errors);
				}
			}
		});

		final Button buttonErrModify = new Button(buttonGroup_1, SWT.NONE);
		buttonErrModify.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewerErrInfo
						.getSelection();
				if (selection.isEmpty()) {
					MessageDialog
							.openInformation(
									null,
									Messages
											.getString("ValidateFilePropertiesPart.remend"), //$NON-NLS-1$
									Messages
											.getString("ValidateFilePropertiesPart.choosetheedititem")); //$NON-NLS-1$
				} else {
					ErrValidateModefiyDialog dialog = new ErrValidateModefiyDialog(
							Display.getDefault().getShells()[0],
							((String) selection.getFirstElement()));
					if (dialog.open() == InputDialog.OK) {
						String error = dialog.getError();

						String[] errorInfo = error.split("::"); //$NON-NLS-1$

						Map<String, String> errors = validate.getErrorInfos();
						errors.put(errorInfo[0], errorInfo[1]);
						validateModel.updateErrorinfo(errors);
						tableViewerErrInfo.setInput(errors);
					}
				}
			}
		});
		toolkit.adapt(buttonErrModify, true, true);
		buttonErrModify.setText(Messages
				.getString("ValidateFilePropertiesPart.edit")); //$NON-NLS-1$
		buttonErrModify.setLayoutData(new GridData(58, SWT.DEFAULT));

		GridData gridData3 = new GridData(SWT.CENTER, SWT.CENTER, false, false);
		gridData3.widthHint = 60;

		final Button buttonErrDel = new Button(buttonGroup_1, SWT.NONE);
		buttonErrDel.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewerErrInfo
						.getSelection();
				if (selection.isEmpty()) {
					MessageDialog
							.openInformation(
									null,
									Messages
											.getString("ValidateFilePropertiesPart.remend"), //$NON-NLS-1$
									(Messages
											.getString("ValidatePart.choosetheitemfordelete"))); //$NON-NLS-1$
				} else {
					if (MessageDialog
							.openConfirm(
									null,
									(Messages
											.getString("ValidatePart.deleteerrormessage")), //$NON-NLS-1$
									(Messages
											.getString("ValidatePart.confirmdeleteerrormessage")))) { //$NON-NLS-1$
						Map<String, String> errors = validate.getErrorInfos();
						errors.remove(((String) selection.getFirstElement())
								.split("::")[0]); //$NON-NLS-1$
						validateModel.updateErrorinfo(errors);
						tableViewerErrInfo.setInput(errors);
					}
				}
			}
		});
		toolkit.adapt(buttonErrDel, true, true);
		buttonErrDel.setText(Messages
				.getString("ValidateFilePropertiesPart.delete")); //$NON-NLS-1$
		buttonErrDel.setLayoutData(gridData3);
		final GridData gd_buttonErrAdd = new GridData();
		gd_buttonErrAdd.horizontalIndent = 5;
		adaptRecursively(toolkit, composite);
		final GridData gd_buttonErrAdd_1 = new GridData();
		gd_buttonErrAdd_1.horizontalIndent = 5;
		addButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		editorButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		delButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		upButton.setLayoutData(new GridData(60, SWT.DEFAULT));
		downButton.setLayoutData(new GridData(60, SWT.DEFAULT));

		final Label label_5 = new Label(composite, SWT.NONE);
		label_5.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		toolkit.adapt(label_5, true, true);
		new Label(composite, SWT.NONE);
		new Label(composite, SWT.NONE);
		new Label(composite, SWT.NONE);
		new Label(composite, SWT.NONE);
		new Label(composite, SWT.NONE);
		modifyErrValidate();
		this.inital();
		return composite;
	}

	protected void modifyParameter() {
		tableLabelProvider.setRowid(0);
		// 建立一个表格单元编辑器
		CellEditor[] editors = new CellEditor[2];
		editors[0] = null;
		editors[1] = new TextCellEditor(argstable);
		// 设置列属性
		argsTableViewer.setColumnProperties(new String[] {
				ARGDIALOG_ELEMENT_ID, ARGDIALOG_ELEMENT_ARG }); //$NON-NLS-1$ //$NON-NLS-2$
		// 设置表格单元的编辑器
		argsTableViewer.setCellEditors(editors);
		// 设置表格单元的修改器
		argsTableViewer.setCellModifier(new TableViewerCellModifier(
				argsTableViewer, tableLabelProvider, this.validateModel,
				this.validate.getArgs()));
	}

	private void modifyErrValidate() {
		CellEditor[] editors = new CellEditor[2];
		editors[0] = null;
		editors[1] = new TextCellEditor(ErrInfoTable);
		this.tableViewerErrInfo.setColumnProperties(new String[] {
				ERRORDIALOG_ELEMENT_KEY, ERRORDIALOG_ELEMENT_VALUE });
		this.tableViewerErrInfo.setCellEditors(editors);
		tableViewerErrInfo
				.setCellModifier(new TableViewerCellModifierForErrValidate(
						tableViewerErrInfo, validateModel, this.validate
								.getErrorInfos()));

	}

	protected String getSectionDescription() {
		return Messages
				.getString("ValidateFilePropertiesPart.validatefieproperties"); //$NON-NLS-1$
	}

	protected String getSectionTitle() {
		return Messages
				.getString("ValidateFilePropertiesPart.validatefiepropertyconfigure"); //$NON-NLS-1$
	}

	private boolean textIsNull(String textValue) {
		if (keyText.getText().equals("") || keyText.getText() == null) { //$NON-NLS-1$
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ValidateFilePropertiesPart.remend1"), //$NON-NLS-1$
							Messages
									.getString("ValidateFilePropertiesPart.writemessagecannotempty")); //$NON-NLS-1$
			return true;
		}
		return false;
	}
	
	
	
	private void classTextChange(String str) {
		if (!this.textIsNull(str)) {
			this.validateModel.updateValidateChildValue(
					ValidateModel.VALIDATE_ELEMENT_CLASS, str); //$NON-NLS-1$
		}
	}

	private void descriptionTextChange(String str) {
		this.validateModel.updateValidateChildValue(
				ValidateModel.VALIDATE_ELEMENT_DESCRIPTION, str); //$NON-NLS-1$
	}

	private void jsTextChange(String str) {
		this.validateModel.updateValidateChildValue(
				ValidateModel.VALIDATE_ELEMENT_JS_METHOD_NAME, str); //$NON-NLS-1$
	}

	private void cusJsTextChange(String str) {
		this.validateModel.updateValidateChildValue(
				ValidateModel.VALIDATE_ELEMENT_CUSTOM_JS_METHOD, str); //$NON-NLS-1$
	}

	private void doAdd() {
		String inputArg;

		InputDialog dlg = new InputDialog(
				null,
				Messages.getString("ValidateFilePropertiesPart.addparameter"), Messages.getString("ValidatePart.pleasewriteparameter"), //$NON-NLS-1$ //$NON-NLS-2$
				ValidateModel.ARGS_ELEMENT_ARG, new InputValidator()); //$NON-NLS-1$

		if (dlg.open() == InputDialog.OK) {
			inputArg = dlg.getValue();

			List<String> args = this.validate.getArgs();

			args.add(inputArg);
			tableLabelProvider.setRowid(0);
			argsTableViewer.setInput(args);
			this.validateModel.updateArg(args);
		}
	}

	private void doEdit() {
		IStructuredSelection selection = (IStructuredSelection) argsTableViewer
				.getSelection();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ValidateFilePropertiesPart.remend2"), Messages.getString("ValidateFilePropertiesPart.chooseitemforedit")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			String editValue;
			List<String> args = this.validate.getArgs();
			int index = argsTableViewer.getTable().getSelectionIndex();
			String argsVO = (String) args.get(index);
			InputDialog dlg = new InputDialog(
					null,
					Messages
							.getString("ValidateFilePropertiesPart.editparameter"), Messages.getString("ValidateFilePropertiesPart.pleasewriteparametername"), //$NON-NLS-1$ //$NON-NLS-2$
					argsVO, new InputValidator());
			if (dlg.open() == InputDialog.OK) {
				editValue = dlg.getValue();
				args.set(index, editValue);
				tableLabelProvider.setRowid(0);
				argsTableViewer.setInput(args);
				this.validateModel.updateArg(args);
			}
		}
	}

	private void doRemove() {
		IStructuredSelection selection = (IStructuredSelection) argsTableViewer
				.getSelection();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ValidateFilePropertiesPart.remend3"), Messages.getString("ValidateFilePropertiesPart.pleasechooseitemforedit")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			if (MessageDialog
					.openConfirm(
							null,
							Messages
									.getString("ValidateFilePropertiesPart.deleteparmeter"), Messages.getString("ValidateFilePropertiesPart.confirmdeleteparameter"))) { //$NON-NLS-1$ //$NON-NLS-2$
				if (argstable.getSelectionCount() > 0) {
					List<String> args = this.validate.getArgs();
					int item = argstable.getSelectionIndex();
					args.remove(item);
					this.validateModel.updateArg(args);
					tableLabelProvider.setRowid(0);
					argsTableViewer.setInput(args);
				}
			}
		}
	}

	@SuppressWarnings("unchecked")//$NON-NLS-1$
	private void doUp() {
		IStructuredSelection selection = (IStructuredSelection) argsTableViewer
				.getSelection();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ValidateFilePropertiesPart.remend4"), Messages.getString("ValidateFilePropertiesPart.chooseonerecord")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			Table table = argsTableViewer.getTable();
			if (table.getItemCount() > 1) {
				if (table != null) {
					int i = table.getSelectionIndex();
					List<String> args = this.validate.getArgs();
					if (i > 0) {
						String argsVO = (String) args.get(i);
						List<String> argsVolist = (List<String>) argsTableViewer
								.getInput();
						argsVolist.remove(argsVO);
						argsTableViewer.remove(argsVO);
						args.add(i - 1, argsVO);
						tableLabelProvider.setRowid(0);
						argsTableViewer.setInput(argsVolist);
						validateModel.updateArg(argsVolist);
						table.setSelection(i - 1);
					}
				}
			}
		}
	}

	@SuppressWarnings("unchecked")//$NON-NLS-1$
	private void doDown() {
		IStructuredSelection selection = (IStructuredSelection) argsTableViewer
				.getSelection();
		if (selection.isEmpty()) {
			MessageDialog
					.openInformation(
							null,
							Messages
									.getString("ValidateFilePropertiesPart.remend5"), Messages.getString("ValidateFilePropertiesPart.pleasechooseonerecord")); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			Table table = argsTableViewer.getTable();
			if (table.getItemCount() > 1) {
				if (table != null) {
					int i = table.getSelectionIndex();
					if (i < table.getItemCount() - 1) {
						List<String> args = this.validate.getArgs();
						String argsVO = (String) args.get(i);
						List<String> argsVolist = (List<String>) argsTableViewer
								.getInput();
						argsVolist.remove(argsVO);
						argsTableViewer.remove(argsVO);
						args.add(i + 1, argsVO);
						tableLabelProvider.setRowid(0);
						argsTableViewer.setInput(argsVolist);
						validateModel.updateArg(argsVolist);
						table.setSelection(i + 1);
					}
				}
			}
		}
	}

	private void inital() {
		this.descriptionText.setText(this.validate.getDescription());
		this.keyText.setText(this.validate.getKey());
		this.nameText.setText(this.validate.getName());
		this.classText.setText(this.validate.getClassTypeStr());
		this.jsValText.setText(this.validate.getJSMethodName());
		this.cusValText.setText(this.validate.getCustemJSMethodInfo());

		argstable.removeAll();
		argsTableViewer.setInput(this.validate.getArgs());

		ErrInfoTable.removeAll();
		tableViewerErrInfo.setInput(this.validate.getErrorInfos());

	}

	// 验证输入信息类
	class InputValidator implements IInputValidator {
		public String isValid(String newText) {
			if (SaturnValidation.isEmpty(newText)) {
				return Messages
						.getString("ValidateFilePropertiesPart.parametervaluecannotempty"); //$NON-NLS-1$
			} else if (SaturnValidation.isBadWord(newText)) {
				return Messages
						.getString("ValidateFilePropertiesPart.cannotwriteillegalchracter"); //$NON-NLS-1$
			} else if (newText.length() > 50) {
				return (Messages.getString("ValidatePart.MaxLength")); //$NON-NLS-1$
			} else {
				return null;
			}
		}
	}

}
